package com.spring.sunflower.anchor

import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.makeramen.roundedimageview.RoundedImageView
import com.spring.sunflower.R
import com.spring.sunflower.bean.VideoPlayBean
import com.spring.sunflower.util.DisplayUtils

/**
 * Created by Kevin on 2021/8/23<br/>
 *
 * Describe:<br/>
 */
class VideoShowAdapter(layoutResId: Int, data: MutableList<VideoPlayBean.DatasBean>?) :
    BaseQuickAdapter<VideoPlayBean.DatasBean, BaseViewHolder>(layoutResId, data) {
    override fun convert(holder: BaseViewHolder, item: VideoPlayBean.DatasBean) {
        val imageCover: RoundedImageView = holder.getView(R.id.rivCover)
        val ivPlay: ImageView = holder.getView<ImageView>(R.id.ivPlay)
        val layoutParams = ConstraintLayout.LayoutParams(-2, -2)
        val screenWidth = DisplayUtils.getScreenWidth(context)
        val i = DisplayUtils.dip2px(context, 45f)
        val imageWidth = (screenWidth - i) / 2
        layoutParams.width = imageWidth
        layoutParams.height = imageWidth * 4 / 3
        imageCover.layoutParams = layoutParams
        Glide.with(context)
            .load(item.videoFirstPhotoUrl)
            .placeholder(R.drawable.ic_placeholder)
            .error(item.photo)
            .into(imageCover)
    }
}